import Vue from 'vue'
import VueI18n from 'vue-i18n'
import { Plugin } from '@nuxt/types'

import { messages } from '@/locales'

Vue.use(VueI18n)

const i18nPlugin: Plugin = (ctx) => {
  const { app } = ctx
  app.i18n = new VueI18n({
    messages,
    locale: app.$cookies.get('lang') || 'zh',
    fallbackLocale: 'zh', // 默认国际化
    silentTranslationWarn: true
  })
}

export default i18nPlugin
